# 类似于django里的 path + 视图函数
# APIRouter 用于定义多个路由接口，并可以将它们组织成模块化、可复用的部分。

from fastapi import Request
# 类似于django里的 path
from fastapi import APIRouter
# 生成路由对象
api_re = APIRouter()

@api_re.get("/kk")
async def kk():
    return {"message":"B站程序员科科测试"}

@api_re.post("/post")
async def post_test():
    return {"method": "post方法"}


# # ret返回给前端 > data数据+meta状态码和消息
# ret = {
#     "data": {},
#     "meta": {
#         "status": 200,
#         "message": ""
#     }
# }
#
# @api_re.post("/register")
# async def register(request: Request):
#     json_data = await request.json()
#     username = json_data['username']
#     password = json_data['password']
#     user = await Guanli.filter(username=username, password=password)
#     if len(user) != 0:
#         ret["data"]["username"] = username
#         ret["meta"]["status"] = 500
#         ret["meta"]["message"] = "当前注册"
#     else:
#         await Guanli.create(username=username, password=password)
#         ret["data"]["username"] = username
#         ret["meta"]["message"] = "注册成功"
#
#     return ret